﻿import Vue from 'vue';
import VueRouter from 'vue-router';
import store from '../vuex/store';
import Util from '../common/util';
import iView from 'iview';
import Cookies from 'js-cookie';

Vue.use(VueRouter);


let router_project_name = Util.projectName();

/**
 * 定义基础路由
 */
const page404 = {
    path: router_project_name + '/*',
    name: 'error_404',
    meta: {
        title: '404-页面不存在'
    },
    component: resolve => { require(['../pages/basic/error_page/404.vue'], resolve); }
};

const page401 = {
    path: router_project_name + '/401',
    meta: {
        title: '401-权限不足'
    },
    name: 'error_401',
    component: resolve => { require(['../pages/basic/error_page/401.vue'], resolve); }
};

const page500 = {
    path: router_project_name + '/500',
    meta: {
        title: '500-服务端错误'
    },
    name: 'error_500',
    component: resolve => { require(['../pages/basic/error_page/500.vue'], resolve); }
};

const locking = {
    path: router_project_name + '/locking',
    name: 'locking',
    component: resolve => { require(['../pages/basic/locking-page/locking-page.vue'], resolve); }
};

/**
 * 定义基础路由
 */
const basicRoute = {
	path: '/' + router_project_name,
	component: (resolve) => require(['../pages/framework/index.vue'], resolve),
	meta: {
		title: '首页'
	},
	children: [
		{
			path: '',
			component: (resolve) => require(['../pages/framework/content.vue'], resolve),
			children: [
				{
					path: router_project_name + '/demo',
					component: (resolve) => require(['../pages/demo/demo.vue'], resolve),
				},
				{
					path: router_project_name + '/demo/new',
					component: (resolve) => require(['../pages/demo/demo1.vue'], resolve),
				},
				{
					path: router_project_name + '/datadict',
					component: (resolve) => require(['../pages/basic/datadict/list.vue'], resolve),
					name: 'sys_datadict_list',
					meta: {
						title: '数据字典'
					}
				},
				{
					path: router_project_name + '/user',
					component: (resolve) => require(['../pages/basic/user/list.vue'], resolve),
					name: 'sys_user_list',
					meta: {
						title: '成员管理'
					}
				},
				{
					path: router_project_name + '/role',
					component: (resolve) => require(['../pages/basic/role/list.vue'], resolve),
					name: 'sys_role_list',
					meta: {
						title: '部门管理'
					}
				},
				{
				 	path: router_project_name + '/resource',
				 	component: (resolve) => require(['../pages/basic/resource/list.vue'], resolve),
				 	name: 'sys_resource_list',
				 	meta: {
						title: '资源菜单'
					}
				},
				{
				 	path: router_project_name + '/resource/perms/:resourceId/:rsv_',
				 	component: (resolve) => require(['../pages/basic/resource/permission.vue'], resolve),
				 	name: 'sys_resource_permission',
				 	meta: {
						title: '资源权限管理'
					}
				},		
				{
				 	path: router_project_name + '/profile',
				 	component: (resolve) => require(['../pages/basic/profile/index.vue'], resolve),
				 	name: 'sys_account_profile',
				 	meta: {
						title: '账户设置'
					}
				},
				{
				 	path: router_project_name + '/im/single',
				 	component: (resolve) => require(['../pages/plugins/im-service/single/index.vue'], resolve),
				 	name: 'sys_single_im',
				 	meta: {
						title: '单客服设置'
					}
				},
				{
				 	path: router_project_name + '/im/multi',
				 	component: (resolve) => require(['../pages/plugins/im-service/multi/list.vue'], resolve),
				 	name: 'sys_multi_im',
				 	meta: {
						title: '多客服设置'
					}
				},
				{
				 	path: router_project_name + '/imgs',
				 	component: (resolve) => require(['../pages/basic/imgs/index.vue'], resolve),
				 	name: 'sys_imgs',
				 	meta: {
						title: '图片管理'
					}
				},
				{
				 	path: router_project_name + '/index',
				 	component: (resolve) => require(['../pages/ops/index/index.vue'], resolve),
				 	name: 'sys_index',
				 	meta: {
						title: '系统概览'
					}
				}
			]
		}
	]
};

const busRoute2 = [
	{
		path: router_project_name + '/orderDetail',
		component: (resolve) => require(['../pages/ops/order/detail.vue'], resolve),
		name: 'ms_orderDetail_detail',
		meta: {
			title: '订单详情'
		}
	}
];

/**
 * 业务路由配置
 */
const busRoute = {
	path: '/' + router_project_name,
	component: (resolve) => require(['../pages/framework/index.vue'], resolve),
	meta: {
		title: '首页',
		name: ''
	},
	children: [
		{
			path: '',
			component: (resolve) => require(['../pages/framework/content.vue'], resolve),
			children: [
				//王婷婷
				{
				 	path: router_project_name + '/property',
				 	component: (resolve) => require(['../pages/ops/property/list.vue'], resolve),
				 	name: 'ops_property_list',
				 	meta: {
						title: '属性管理'
					}
				},				
				{
				 	path: router_project_name + '/productCategory',
				 	component: (resolve) => require(['../pages/ops/productCategory/list.vue'], resolve),
				 	name: 'ops_productCategory_list',
				 	meta: {
						title: '基础类目管理'
					}
				},
				//app类目聚合页面
				{
				 	path: router_project_name + '/appCategory',
				 	component: (resolve) => require(['../pages/ops/appCategory/appCategoryList.vue'], resolve),
				 	name: 'ops_appCategory_list',
				 	meta: {
						title: 'app类目管理'
					}
				},
				//品牌管理
				{
					path: router_project_name + '/brandManager',
					component: (resolve) => require(['../pages/ops/brandManager/brandManager.vue'], resolve),
					name: 'ops_brandManage_brandList',
					meta: {
					   title: '品牌管理'
				   }
			  	},
				{
				 	path: router_project_name + '/product',
				 	component: (resolve) => require(['../pages/ops/product/list.vue'], resolve),
				 	name: 'ops_product_list',
				 	meta: {
						title: '商品列表'
					}
				},
				{
				 	path: router_project_name + '/product/productReview',
				 	component: (resolve) => require(['../pages/ops/product/productReview.vue'], resolve),
				 	name: 'ops_product_productReview',
				 	meta: {
						title: '商品评论'
					}
				},
				{
				 	path: router_project_name + '/merchant',
				 	component: (resolve) => require(['../pages/ops/merchant/list.vue'], resolve),
				 	name: 'ops_merchant_list',
				 	meta: {
						title: '商户列表'
					}
				},
				{
					path: router_project_name + '/messagesms',
					component: (resolve) => require(['../pages/ops/messagesms/list.vue'], resolve),
					name: 'ops_messagesms_list',
				 	meta: {
						title: '短信消息'
					}
				},
				{
					path: router_project_name + '/messagesms/smsList',
					component: (resolve) => require(['../pages/ops/messagesms/smsList.vue'], resolve),
					name: 'ops_messagesms_smsList',
				 	meta: {
						title: '系统消息'
					}
				},
				{
					path: router_project_name + '/operationLog',
					component: (resolve) => require(['../pages/ops/loge/operationList.vue'], resolve),
					name: 'ops_operationLog_list',
				 	meta: {
						title: '操作日志'
					}
				},
				{
					path: router_project_name + '/loginLog',
					component: (resolve) => require(['../pages/ops/loge/loginList.vue'], resolve),
					name: 'ops_loginLog_list',
				 	meta: {
						title: '登录日志'
					}
				},
				//纪文亭
				{
					path: router_project_name + '/merchantAudit',
					component: (resolve) => require(['../pages/ops/merchantAudit/list.vue'], resolve),
					name: 'ops_merchantAudit_list',
				 	meta: {
						title: '商户入驻管理'
					}
				},
				{
					path: router_project_name + '/platformAccount',
					component: (resolve) => require(['../pages/ops/platformAccount/list.vue'], resolve),
					name: 'ops_platformAccount_list',
				 	meta: {
						title: '平台资金管理'
					}
				},
				{
					path: router_project_name + '/merchantAccountRecord',
					component: (resolve) => require(['../pages/ops/merchantAccountRecord/list.vue'], resolve),
					name: 'ops_merchantAccountRecord_list',
					meta: {
						title: '商户资金流水'
					}
				},
				{
					path: router_project_name + '/withdrawRecord',
					component: (resolve) => require(['../pages/ops/withdrawRecord/list.vue'], resolve),
					name: 'ops_withdrawRecord_list',
				 	meta: {
						title: '提现申请管理'
					}
				},
				{
					path: router_project_name + '/refund',
					component: (resolve) => require(['../pages/ops/refund/list.vue'], resolve),
					name: 'ops_refund_list',
				 	meta: {
						title: '退款管理'
					}
				},
				{
					path: router_project_name + '/refundDetail',
					component: (resolve) => require(['../pages/ops/refund/detail.vue'], resolve),
					name: 'ops_refundDetail_detail',
				 	meta: {
						title: '退款详情'
					}
				},
				{
					path: router_project_name + '/member',
					component: (resolve) => require(['../pages/ops/member/list.vue'], resolve),
					name: 'ops_member_list',
				 	meta: {
						title: '会员管理'
					}
				}, 
				{
					path: router_project_name + '/pushMessage',
					component: (resolve) => require(['../pages/ops/pushMessage/list.vue'], resolve),
					name: 'ops_pushMessage_list',
				 	meta: {
						title: '推送'
					}
				}, 
				//刘吴奇
				{
					path: router_project_name + '/sensitiveWord',
					component: (resolve) => require(['../pages/ops/sensitiveWord/list.vue'], resolve),
					name: 'ops_sensitiveWord_list',
					meta: {
						title: '敏感词'
					}
				},
				{
					path: router_project_name + '/area',
					component: (resolve) => require(['../pages/ops/area/list.vue'], resolve),
					name: 'ops_area_list',
					meta: {
						title: '地区管理'
					}
				},
				{
					path: router_project_name + '/express',
					component: (resolve) => require(['../pages/ops/express/list.vue'], resolve),
					name: 'ops_express_list',
					meta: {
						title: '物流公司'
					}
				},
				{
					path: router_project_name + '/tag',
					component: (resolve) => require(['../pages/ops/tag/list.vue'], resolve),
					name: 'ops_tag_list',
					meta: {
						title: '标签管理'
					}
				},	
				{
					path: router_project_name + '/banner',
					component: (resolve) => require(['../pages/ops/banner/list.vue'], resolve),
					name: 'ops_banner_list',
					meta: {
						title: 'banner列表'
					}
				},
				{
					path: router_project_name + '/banner/edit',
					component: (resolve) => require(['../pages/ops/banner/edit.vue'], resolve),
					name: 'ops_banner_edit',
					meta: {
						title: 'banner编辑'
					}
				},
				//demo3
				{
					path: router_project_name + '/demo3',
					component: (resolve) => require(['../pages/demo/demo3.vue'], resolve),
				},
				{
					path: router_project_name + '/feedback',
					component: (resolve) => require(['../pages/ops/feedback/list.vue'], resolve),
					name: 'ops_feedback_list',
					meta: {
						title: '问题反馈'
					}
				},
				{
					path: router_project_name + '/platformFinanceSettingEdit',
					component: (resolve) => require(['../pages/ops/platformFinanceSetting/list.vue'], resolve),
					name: 'ops_platformFinanceSetting_edit',
				 	meta: {
						title: '提现手续费设置'
					}
				},
				{
					path: router_project_name + '/language',
					component: (resolve) => require(['../pages/ops/language/list.vue'], resolve),
					name: 'ops_language_list',
				 	meta: {
						title: '语言列表服务'
					}
				},
				{
					path: router_project_name + '/topic',
					component: (resolve) => require(['../pages/ops/topic/list.vue'], resolve),
					name: 'ops_topic_list',
				 	meta: {
						title: '主题服务列表'
					}
				},
				{
					path: router_project_name + '/topic/edit',
					component: (resolve) => require(['../pages/ops/topic/edit.vue'], resolve),
					name: 'ops_topic_edit',
				 	meta: {
						title: '编辑主题服务'
					}
				},
				{
					path: router_project_name + '/topic/add',
					component: (resolve) => require(['../pages/ops/topic/add.vue'], resolve),
					name: 'ops_topic_add',
				 	meta: {
						title: '新增主题服务'
					}
				},
				{
					path: router_project_name + '/topic/new',
					component: (resolve) => require(['../pages/ops/topic/new.vue'], resolve),
					name: 'ops_topic_new',
				 	meta: {
						title: '发布主题服务'
					}
				},
				{
					path: router_project_name + '/topic/modify',
					component: (resolve) => require(['../pages/ops/topic/modify.vue'], resolve),
					name: 'ops_topic_modify',
				 	meta: {
						title: '编辑主题服务'
					}
				},				
				{
					path: router_project_name + '/exchangeRate',
					component: (resolve) => require(['../pages/ops/exchangeRate/list.vue'], resolve),
					name: 'ops_exchange_set',
				 	meta: {
						title: '汇率设置'
					}
				},
				{
					path: router_project_name + '/appVersionManage',
					component: (resolve) => require(['../pages/ops/appVersionManage/appList.vue'], resolve),
					name: 'ops_app_version_manage',
				 	meta: {
						title: '版本管理'
					}
				},
				{
					path: router_project_name + '/transfer',
					component: (resolve) => require(['../pages/ops/transfer/list.vue'], resolve),
					name: 'ops_transfer_list',
				 	meta: {
						title: '中转仓列表'
					}
				},
				{
					path: router_project_name + '/logistics',
					component: (resolve) => require(['../pages/ops/logistics/list.vue'], resolve),
					name: 'ops_logistics_list',
				 	meta: {
						title: '物流信息列表'
					}
				},
				// panderWu
				{
					path: router_project_name + '/recoManager',
					component: (resolve) => require(['../pages/ops/recoManager/list.vue'], resolve),
					name: 'ops_reco_list',
				 	meta: {
						title: '推荐列表'
					}
				},
				{
					path: router_project_name + '/recoManager/addReco',
					component: (resolve) => require(['../pages/ops/recoManager/addReco.vue'], resolve),
					name: 'ops_add_banner',
				 	meta: {
						title: '添加banner推荐'
					}
				},
				{
					path: router_project_name + '/activities',
					component: (resolve) => require(['../pages/ops/activities/list.vue'], resolve),
					name: 'ops_activities_list',
				 	meta: {
						title: '活动列表'
					}
				},
				{
					path: router_project_name + '/activities/addActivities',
					component: (resolve) => require(['../pages/ops/activities/add.vue'], resolve),
					name: 'ops_activities_add',
				 	meta: {
						title: '发布活动'
					}
				},
				{
					path: router_project_name + '/topicCategory/list',
					component: (resolve) => require(['../pages/ops/topicCategory/list.vue'], resolve),
					name: 'ops_topicCategory_list',
				 	meta: {
						title: '主题分类列表'
					}
				},
				{
					path: router_project_name + '/topicCategory/details',
					component: (resolve) => require(['../pages/ops/topicCategory/details.vue'], resolve),
					name: 'ops_topicCategory_details',
				 	meta: {
						title: '主题分类详情'
					}
				},
				{
					path: router_project_name + '/order',
					component: (resolve) => require(['../pages/ops/order/list_new.vue'], resolve),
					name: 'ms_order_list',
					meta: {
						title: '订单列表'
					}
				},
				{
					path: router_project_name + '/alliance',
					component: (resolve) => require(['../pages/ops/alliance/list_new.vue'], resolve),
					name: 'ms_alliance_list',
					meta: {
						title: '联盟列表'
					}
				},
				{
					path: router_project_name + '/alliance/partner',
					component: (resolve) => require(['../pages/ops/alliance/partner.vue'], resolve),
					name: 'ms_partner_list',
					meta: {
						title: '合伙人列表'
					}
				},
				{
					path: router_project_name + '/serviceRateSetting',
					component: (resolve) => require(['../pages/ops/serviceRateSetting/list.vue'], resolve),
					name: 'ops_serviceRateSetting_list',
					meta: {
						title: '订单列表'
					}
				},
				{
					path: router_project_name + '/customerServiceTelephone',
					component: (resolve) => require(['../pages/ops/customerServiceTelephone/list.vue'], resolve),
					name: 'ms_customer_telephone_list',
					meta: {
						title: '客服列表'
					}
				},
				// lvpan
				{
					path: router_project_name + '/discountSales',
					component: (resolve) => require(['../pages/ops/discountSales/list.vue'], resolve),
					name: 'ops_discountCoupon_management_list',
					meta: {
						title: '优惠券管理'
					}
				},
				{
					path: router_project_name + '/discountSales/add',
					component: (resolve) => require(['../pages/ops/discountSales/add.vue'], resolve),
					name: 'ops_coupon_add',
				 	meta: {
						title: '发布优惠券服务'
					}
				},
				{
					path: router_project_name + '/discountClass',
					component: (resolve) => require(['../pages/ops/discountClass/list.vue'], resolve),
					name: 'ops_discountClass_list',
				 	meta: {
						title: '限时折扣分类'
					}
				},
				{
					path: router_project_name + '/buyingAgent',
					component: (resolve) => require(['../pages/ops/buyingAgent/list.vue'], resolve),
					name: 'ops_buyingAgent_list',
				 	meta: {
						title: '买手精灵提现'
					} 
				},
				{
					path: router_project_name + '/discountCode',
					component: (resolve) => require(['../pages/ops/discountCode/list.vue'], resolve),
					name: 'ops_discountCode_list',
					 meta: {
					  title: '优惠码列表'
					}
				  },
				{
					path: router_project_name + '/discountSales/add',
					component: (resolve) => require(['../pages/ops/discountCode/add.vue'], resolve),
					name: 'ops_discountCode_add',
					 meta: {
					  title: '新增优惠码'
					}
				}

			]
		}
	]	
};
const busRoute1 = {
	path: router_project_name + '/demo2',
	component: (resolve) => require(['../pages/demo/demo2.vue'], resolve)
};



/**
 * auth true 登录才能访问的页面
 * name 为命名路由,建议不要用于显示中文名称(可以为CODE,由服务端控制显示名称)
 * displayName 为测试新加属性
 */
let routes = [
	locking,
	basicRoute,
	busRoute,
	busRoute1,
	...busRoute2,
	page500,
	page401,
	page404
];


const router = new VueRouter({
	mode: 'history',
    routes:routes
})

router.beforeEach((to, from, next) => {
    iView.LoadingBar.start();
    Util.title(to.meta.title);
    if (Cookies.get('locking') === '1' && to.name !== 'locking') {  // 判断当前是否是锁定状态
    	iView.LoadingBar.finish();
    	next(false);
    	router.push({
    		name: 'locking'
    	});
    } else if (Cookies.get('locking') === '0' && to.name === 'locking') {
    	iView.LoadingBar.finish();
    	next(false);
    } else {
    	//1.处理第一次加载
    	let isFirstLoad = store.getters.framework_firstLoad;
    	if(isFirstLoad) {
    		store.dispatch('authUpdateMenu', {'router': router, 'curr': to});	
    		store.dispatch('frameworkUpdateFirstLoad');
    	}
    	next();
    }
});

router.afterEach(transition => {
    iView.LoadingBar.finish();
    window.scrollTo(0, 0);
});


export default router;
